package app.modules.infrastructure.profile.application.web;

import app.modules.common.dto.web.WebIdDTO;
import app.modules.infrastructure.profile.business.service.ProfileValueService;
import app.modules.infrastructure.profile.dto.web.WebProfileDetailDTO;
import app.modules.infrastructure.profile.dto.web.WebProfileSettingUpdateDTO;
import io.swagger.v3.oas.annotations.Operation;
import jasmine.framework.web.entity.WebResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author mh.z
 */
@RestController
public class ProfileValueController {
    private ProfileValueService profileValueService;

    public ProfileValueController(ProfileValueService profileValueService) {
        this.profileValueService = profileValueService;
    }

    @Operation(summary = "查询配置详情")
    @PostMapping("/api/infrastructure/profile/getProfileDetailById")
    public ResponseEntity<WebResult<WebProfileDetailDTO>> getProfileDetailById(
            @RequestBody WebIdDTO paramDTO) {
        Long recordId = paramDTO.getId();

        WebProfileDetailDTO detailDTO = profileValueService.getProfileDetailById(recordId);
        WebResult result = WebResult.success(detailDTO);

        return result.toOkEntity();
    }

    @Operation(summary = "更新配置值项")
    @PostMapping("/api/infrastructure/profile/updateProfileValue")
    public ResponseEntity<WebResult<Boolean>> updateProfileValue(
            @Valid @RequestBody WebProfileSettingUpdateDTO updateDTO) {
        profileValueService.updateProfileValue(updateDTO);
        WebResult result = WebResult.success();

        return result.toOkEntity();
    }

}
